package com.fr.report.script.core.parser;

import com.fr.report.script.Calculator;
import com.fr.util.Utils;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class PowerExpression extends MathExpression
{
  private static final String POW = "^";
  UnaryExpression[] unarys;

  PowerExpression(UnaryExpression[] paramArrayOfUnaryExpression)
  {
    this.unarys = paramArrayOfUnaryExpression;
  }

  public Object eval(Calculator paramCalculator)
    throws UtilEvalError
  {
    if (this.unarys.length == 0)
      throw new InterpreterError("unaryList should not be empty");
    Object localObject1 = null;
    for (int i = 0; i < this.unarys.length; ++i)
      if (i == 0)
      {
        localObject1 = this.unarys[i].eval(paramCalculator);
      }
      else
      {
        Object localObject2 = this.unarys[i].eval(paramCalculator);
        localObject1 = binaryOperation(localObject1, localObject2, "^");
      }
    return localObject1;
  }

  protected Object ccNINI(String paramString)
  {
    return OperationUtils.ZERO;
  }

  protected Object ccNIPI(String paramString)
  {
    return OperationUtils.NEGATIVE_INFINITY;
  }

  protected Object ccNIRE(Object paramObject, String paramString)
  {
    Number localNumber = Utils.objectToNumber(paramObject, true);
    if (localNumber == null)
      return OperationUtils.NEGATIVE_INFINITY;
    if (localNumber.intValue() < 0)
      return OperationUtils.ZERO;
    return OperationUtils.NEGATIVE_INFINITY;
  }

  protected Object ccPINI(String paramString)
  {
    return OperationUtils.ZERO;
  }

  protected Object ccPIPI(String paramString)
  {
    return OperationUtils.POSITIVE_INFINITY;
  }

  protected Object ccPIRE(Object paramObject, String paramString)
  {
    Number localNumber = Utils.objectToNumber(paramObject, true);
    if (localNumber == null)
      return OperationUtils.POSITIVE_INFINITY;
    if (localNumber.intValue() < 0)
      return OperationUtils.ZERO;
    return OperationUtils.POSITIVE_INFINITY;
  }

  protected Object ccRENI(Object paramObject, String paramString)
  {
    return OperationUtils.ZERO;
  }

  protected Object ccREPI(Object paramObject, String paramString)
  {
    Number localNumber = Utils.objectToNumber(paramObject, true);
    if (localNumber == null)
      return OperationUtils.POSITIVE_INFINITY;
    int i = localNumber.intValue();
    if (i > 0)
      return OperationUtils.POSITIVE_INFINITY;
    if (i == 0)
      return OperationUtils.ZERO;
    return OperationUtils.NEGATIVE_INFINITY;
  }

  protected Object ccRERE(Object paramObject1, Object paramObject2, String paramString)
  {
    return numberOperation(paramObject1, paramObject2, paramString);
  }

  protected Object decimalOperation(BigDecimal paramBigDecimal1, BigDecimal paramBigDecimal2, String paramString)
  {
    return doubleOperation(paramBigDecimal1.doubleValue(), paramBigDecimal2.doubleValue(), paramString);
  }

  protected Object doubleOperation(double paramDouble1, double paramDouble2, String paramString)
  {
    return new Double(Math.pow(paramDouble1, paramDouble2));
  }

  protected Object intOperation(int paramInt1, int paramInt2, String paramString)
  {
    return new Double(Math.pow(paramInt1, paramInt2));
  }

  public void traversal4Tiny(TinyHunter paramTinyHunter)
  {
    for (int i = 0; i < this.unarys.length; ++i)
      this.unarys[i].traversal4Tiny(paramTinyHunter);
  }

  public String exString(Calculator paramCalculator)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    for (int i = 0; i < this.unarys.length; ++i)
    {
      if (i > 0)
        localStringBuffer.append(" ^ ");
      localStringBuffer.append(this.unarys[i].exString(paramCalculator));
    }
    return localStringBuffer.toString();
  }

  public String toString()
  {
    StringBuffer localStringBuffer = new StringBuffer();
    for (int i = 0; i < this.unarys.length; ++i)
    {
      if (i > 0)
        localStringBuffer.append(" ^ ");
      localStringBuffer.append(this.unarys[i]);
    }
    return localStringBuffer.toString();
  }

  public String getExpression(int paramInt1, int paramInt2, int paramInt3, int paramInt4, boolean paramBoolean)
  {
    StringBuffer localStringBuffer = new StringBuffer();
    for (int i = 0; i < this.unarys.length; ++i)
    {
      if (i > 0)
        localStringBuffer.append(" ^ ");
      localStringBuffer.append(this.unarys[i].getExpression(paramInt1, paramInt2, paramInt3, paramInt4, paramBoolean));
    }
    return localStringBuffer.toString();
  }

  public String[] parserParameter()
  {
    ArrayList localArrayList = new ArrayList();
    int i = 0;
    int j = this.unarys.length;
    while (i < j)
    {
      if (this.unarys[i].parserParameter() == null)
        break label55:
      localArrayList.addAll(Arrays.asList(this.unarys[i].parserParameter()));
      label55: ++i;
    }
    return ((String[])localArrayList.toArray(new String[localArrayList.size()]));
  }
}